﻿<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="/WEB-INF/jsp/common/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<style type="text/css">
<!--
.STYLE1 {font-weight: bold}
-->
</style>
<script type="text/javascript" src="${resRoot}/js/alert_message.js"></script>
<body>
<!-- 以下为内容 -->
<div class="main-content1">
<!-- /section:basics/content.breadcrumbs -->
<div class="page-content">
<div class="row">
<div class="col-xs-12" >
<!-- PAGE CONTENT BEGINS -->
<div class="widget-box transparent">
							
	<div class="widget-header widget-header-small">
				<h4 class="widget-title blue smaller">
					<i class="ace-icon fa fa-rss orange"></i>
					菜单信息
				</h4>

												<div class="widget-toolbar">
													<a href="#" class="blue" id="editS" onclick="to_submit();">												
													<i class="ace-icon fa fa-save "></i> 保存菜单信息												</a>
												</div>											
											</div>
											
										<div class="widget-body">
											<div class="widget-main padding-0">
													<!-- #section:pages/profile.feed -->
											<div id="profile-feed-1" class="profile-feed">
											<form id="form1" class="form-horizontal" role="form">
												  
												<div class="space-1"></div>
                                				<div class="form-group">
                                    				<label class="col-sm-3 control-label no-padding-right" for="form-field-1">父级菜单</label>
	                                    			<div class="col-sm-9">
												        <select id="menu" name="parentCode" class="col-xs-9">
                                                        </select>
													</div>
                                  				</div>
                                  				
												<div class="space-1"></div>
                                				<div class="form-group">
                                    				<label class="col-sm-3 control-label no-padding-right" for="form-field-1">菜单代码</label>
	                                    			<div class="col-sm-9">
                                                    	<input name="menuCode" type="text"  id="menuCode" value="" maxlength="50" class="col-xs-9" />
													</div>
                                  				</div>
                                  				
                                  				
												<div class="space-1"></div>
                                				<div class="form-group">
                                    				<label class="col-sm-3 control-label no-padding-right" for="form-field-1">菜单名称</label>
	                                    			<div class="col-sm-9">
	                                                    <input name="menuName" type="text"  value="" maxlength="50" class="col-xs-9" />
													</div>
                                  				</div>
                                  				
												<div class="space-1"></div>
                                				<div class="form-group">
                                    				<label class="col-sm-3 control-label no-padding-right" for="form-field-1">菜单路径</label>
	                                    			<div class="col-sm-9">
	                                                    <input name="url" type="text"  id="url" value="" maxlength="200" class="col-xs-9" />
													</div>
                                  				</div>
                                  				
												<div class="space-1"></div>
                                				<div class="form-group">
                                    				<label class="col-sm-3 control-label no-padding-right" for="form-field-1">描述</label>
	                                    			<div class="col-sm-9">
														<textarea name="remark" id="remark" rows="5" class="col-xs-9" ></textarea>	
													</div>
                                  				</div>
                                  				
                                  				<div class="space-1"></div>
                                				<div class="form-group">
                                    				<label class="col-sm-3 control-label no-padding-right" for="form-field-1">菜单类型</label>
	                                    			<div class="col-sm-9">
	                                                     <input name="menuType" type="radio" value="P" checked="checked" />业务菜单 &nbsp;&nbsp;
	                                                     <input type="radio" name="menuType" value="S"  />仅管理员可见
													</div>
                                  				</div>
                                  				
                                  				
												<div class="space-1"></div>
                                				<div class="form-group">
                                    				<label class="col-sm-3 control-label no-padding-right" for="form-field-1">排序序号</label>
	                                    			<div class="col-sm-9">
	                                                    <input name="orderId" type="text"  value="" maxlength="10" class="col-xs-9" />
													</div>
                                  				</div>
                                  				
												<div class="space-1"></div>
                                				<div class="form-group">
                                    				<label class="col-sm-3 control-label no-padding-right" for="form-field-1">菜单图标</label>
	                                    			<div class="col-sm-9">
	                                                    <input name="icon" type="text"  value="" maxlength="100" class="col-xs-9" />
													</div>
                                  				</div>
                                  				
												<div class="space-1"></div>
                                				<div class="form-group">
                                    				<label class="col-sm-3 control-label no-padding-right" for="form-field-1">菜单打开图标</label>
	                                    			<div class="col-sm-9">
	                                                    <input name="iconopen" type="text"  value="" maxlength="100" class="col-xs-9" />
													</div>
                                  				</div>
                                  				
												<div class="space-1"></div>
                                				<div class="form-group">
                                    				<label class="col-sm-3 control-label no-padding-right" for="form-field-1">状态</label>
	                                    			<div class="col-sm-9">
	                                                     <input name="status" type="radio" value="1" checked="checked" />有效 &nbsp;&nbsp;
	                                                     <input type="radio" name="status" value="0"  />无效
													</div>
                                  				</div>
                                             </form>
										 </div>
									</div>


  <div class="widget-box transparent" style=" margin-bottom:0;">
											<div class="widget-header widget-header-small">
												<h4 class="widget-title blue smaller">
													<i class="ace-icon glyphicon glyphicon-cog orange"></i>
													按钮维护</h4>

												<div class="widget-toolbar">
												
												
													<a href="#modal-table" onclick="showBut();"  data-toggle="modal" class="blue" id="editS">												
													<i class="ace-icon glyphicon glyphicon-plus "></i> 添加按钮												</a>
																													</div>											
											</div>
											</div>

												  <div style="overflow-x:auto;   height:100%">
  <table id="sample-table-1" class="table table-striped table-bordered table-hover" style="margin:0; "  >
    <thead>
      <tr>
        <th align="center" nowrap="nowrap" class="center">序号</th>
        <th nowrap="nowrap" ><strong>按钮代码</strong></th>
		 <th nowrap="nowrap" ><strong>按钮名称</strong></th>
        <th nowrap="nowrap" >操作</th>
      </tr>
    </thead>
  </table>
</div>
	
	<div class="col-xs-12" style="text-align:center"><!-- 按钮行-->
	<div class="clearfix form-actions" style="">
		<button class="btn" type="button" onclick="window.location.href='forwardMenuChildrenList.htm?parentCode=${menu.menuCode}'">
		<i class="ace-icon fa fa-undo bigger-110"></i>返 回</button>
	</div>
</div>

</div>
</div>
</div>
</div>
</div>
                       
	
<script src="${resRoot}/plugin/ace-v1.3/assets/js/jquery.validate.min.js"></script>
<script src="${resRoot}/plugin/jquery-validation/localization/messages_zh.js"></script>

<script type="text/javascript">

        //全局变量  保存menucode信息
        
           var selectmenucode='${menu.menuCode}';
          
		   var menucode='';
		   
		   var errorparam=0;
		   
		  $(document).ready(function(){
		  //加载父级菜单
		  showParentMenu();
		  validateForm();
		    });
		    
		    function to_submit(){
		    	$("#form1").submit();
		    }
		  
		   //ajax加载父级下拉框
		     function showParentMenu(){
		         $.ajax({
		           url : "findMenuByParentId.json",
		           type : "post",
		           data : {parentCode:0},
		           dataType : "json",		           
		           success : function(data){
		             if(data.length > 0){
		               var html="";
		               
		               //一级菜单
		               if(selectmenucode==0){
		                html+="<option value='0'>菜单管理</option>";
		               }else{
		               
		               //二级菜单
		               for(var i=0;i<data.length;i++){
		                if(selectmenucode==data[i].menuCode){
		                 html+="<option value='"+data[i].menuCode+"' selected>"+data[i].menuName+"</option>";
		                }else{
                         html+="<option value='"+data[i].menuCode+"'>"+data[i].menuName+"</option>";		                
		                }
		               }
		               
		               }
		               $("#menu").append(html);
		             }
		           },
		           error : function(){
		             $.Alert('加载父级菜单出现错误！','','');
		           }
		         });
		     }
		     
		    function showBut(that){
		    $.Alert("请先保存菜单信息！");
			}
		   //ajax提交保存菜单信息
		     function do_menusave(){
		     menucode=$.trim($("#menuCode").val());
		    var remarktrim=$.trim($("#remark").val());
		   $("#remark").val(remarktrim);
		   var urltrim=$.trim($("#url").val());
		   $("#url").val(urltrim);
		      $.ajax({
		           url : "saveMenu.json",
		           type : "post",
		           data : $("#form1").serializeObject(),
		           dataType : "json",		           
		           success : function(data){
		            errorparam=0; 
		            $.Alert(data.message,'',reloadpage);
		           },
		           error : function(){
		             $.Alert('服务异常，请稍后尝试！','','');
		             errorparam=1;
		           }
		         });
		     }
		     
		     jQuery.validator.addMethod("validKeyCode",function(value,element){
		       var reg = /^[a-zA-Z0-9_]*$/;
		       return this.optional(element) || reg.test(value);
		    },"只能输入字母、下划线和数字");
		     
		      function validateForm(){
		       return $("#form1").validate({
		         errorElement : 'span',
				 errorClass : 'help-block',
				 focusInvalid : false,
				 rules : {
				   "menuCode" : {
				    required : true,
				    validKeyCode:true,
				    remote:{
							url : '../../auth/menu/validMenuCode.json',
							type : "post",
							async : false,
						    data : {menuCode:function(){return $.trim($("#menuCode").val())}}
						}
				   },
				   "menuName" : {
				     required : true
				   },
				   "url" : {
				    required : true
				   },
				   "remark" : {
				    required : true,
					 maxlength:500
				   },
				   "orderId" : {
				    required : true,
				    number:true				    
				   }
				 },
				 
				 messages : {
				   "menuCode" : {
				    remote : "该菜单代码已存在，请重新添加"
				   }
				 },
				 
				 highlight: function (e) {
					$(e).closest('.form-group').removeClass('has-info').addClass('has-error');
				},
				success: function (e) {
					$(e).closest('.form-group').removeClass('has-error');//.addClass('has-info');
					$(e).remove();
				},
				 errorPlacement: function (error, element) {
						if(element.is(':checkbox') || element.is(':radio')) {
							var controls = element.closest('div[class*="col-"]');
							if(controls.find(':checkbox,:radio').length > 1) controls.append(error);
							else error.insertAfter(element.nextAll('.lbl:eq(0)').eq(0));
						}
						else if(element.is('.select2')) {
							error.insertAfter(element.siblings('[class*="select2-container"]:eq(0)'));
						}
						else if(element.is('.chosen-select')) {
							error.insertAfter(element.siblings('[class*="chosen-container"]:eq(0)'));
						}
						else if(element.is('textarea')) {
							error.appendTo(element.parent());
						}
						else if(element.is('input[type=text]')) {
							error.appendTo(element.parent());
						}
						else error.insertAfter(element.parent());
					},
					submitHandler: function (form) {
						do_menusave();
					},
					invalidHandler: function (form) {
					}
		       });
		     }
		     
		     //到编辑页面 
		     function reloadpage(){
		     addRefreshTree(0);
		     window.location.href='toEditMenu.htm?menuCode='+menucode;
		     }
		     
		     function addRefreshTree(typeVal){
		     	parent.refreshTree(typeVal);
		     }
		     
		</script>
		
		</body>
</html>
